/*============================
*	File Name: Dog.c
*	Created Date: 12/16/2021 10:51:18 PM
*	Last Modified Date:12/17/2021 11:45:21 AM
*	Author: mistgc
*	Email: georgecai0908@outlook.com
============================*/
#include "Dog.h"
#include <stdlib.h>
#include <stdio.h>

static void Dog_eat_(Pet const * const me);								//Dog重载虚函数表

void Dog_ctor(Dog * const me, char *name, int color){
	//首先初始化父类对象
	static PetVTBL const vtbl= {
		&Dog_eat_
	};
	Pet_ctor((&me->super), name);

	me->super.vptr = &vtbl;									//重载vptr
	me->color = color;
}

char *Dog_getColor(Dog const * const me){
	char *temp = (char *)malloc(sizeof(char) * 5);
	switch(me->color){
		case 1:
			temp = "white";
			break;
		case 2:
			temp = "Black";
			break;
		case 3:
			temp = "Yellow";
			break;
	}
	return temp;
}

static void Dog_eat_(Pet const * const me){
	char *color = Dog_getColor((Dog const * const)me);
	printf("%s dog ,%s is eating...\n", color, Pet_getName(me));
	free(color);					//If not, it will be memory leaks.
}
